local RegisterView = class("RegisterView",function()
		local registerView =  display.newLayer()
    return registerView
end)

RegisterView.BT_REGISTER = 1
RegisterView.BT_RETURN	 = 2
RegisterView.BT_AGREEMENT= 3
RegisterView.CBT_AGREEMENT = 4
RegisterView.BT_CODE = 5

RegisterView.bAgreement = true
local ExternalFun = appdf.req(appdf.EXTERNAL_SRC .. "ExternalFun")

function RegisterView:ctor()
	AudioEngine.playEffect("sound/bindaccount.mp3")
	local this = self
	self:setContentSize(yl.WIDTH,yl.HEIGHT)

	local  btcallback = function(ref, type)
        if type == ccui.TouchEventType.ended then
         	this:onButtonClickedEvent(ref:getTag(),ref)
        end
    end
        local rootLayer, csbNode = ExternalFun.loadRootCSB("popView/registLayer.csb", self)
		ExternalFun.FixScaleUI(csbNodes,true)
    --Top返回

    csbNode:getChildByName("closebt")
		:setTag(RegisterView.BT_RETURN)
		:addTouchEventListener(btcallback)

    	--注册按钮
	csbNode:getChildByName("Button_1_0")
		:setTag(RegisterView.BT_REGISTER)
		:addTouchEventListener(btcallback)

		 	--注册按钮
	csbNode:getChildByName("Button_1")
		:setTag(RegisterView.BT_CODE)
		:addTouchEventListener(btcallback)


	--账号输入
	self.edit_Account = ccui.EditBox:create(cc.size(505,67), ccui.Scale9Sprite:create("popView/inputicon.png"))
		:move(723,507)
		:setAnchorPoint(cc.p(0.5,0.5))
		:setFontName("fonts/round_body.ttf")
		:setPlaceholderFontName("fonts/round_body.ttf")
		:setFontSize(24)
		:setPlaceholderFontSize(24)
		:setMaxLength(31)
		:setInputMode(cc.EDITBOX_INPUT_MODE_SINGLELINE)
		:setPlaceHolder("请输入手机号")
		:addTo(self)

	--密码提示
--	display.newSprite("Regist/icon_regist_tip.png")
--		:move(293,450)
--		:addTo(self)
--	display.newSprite("Regist/text_regist_password.png")
--		:move(392,450)
--		:addTo(self)

	--密码输入	
	self.edit_Password = ccui.EditBox:create(cc.size(305,67), ccui.Scale9Sprite:create("popView/inputicon.png"))
		:move(623,353)
		:setAnchorPoint(cc.p(0.5,0.5))
		:setFontName("fonts/round_body.ttf")
		:setPlaceholderFontName("fonts/round_body.ttf")
		:setFontSize(24)
		:setPlaceholderFontSize(24)
		:setMaxLength(26)
		:setInputFlag(cc.EDITBOX_INPUT_FLAG_PASSWORD)
		:setInputMode(cc.EDITBOX_INPUT_MODE_SINGLELINE)
		:setPlaceHolder("请输入验证码")
		:addTo(self)

--	--确认密码提示
--	display.newSprite("Regist/icon_regist_tip.png")
--		:move(293,358)
--		:addTo(self)
--	display.newSprite("Regist/text_regist_confirm.png")
--		:move(392,358)
--		:addTo(self)

--	--确认密码输入	
--	self.edit_RePassword = ccui.EditBox:create(cc.size(490,67), ccui.Scale9Sprite:create("Regist/text_field_regist.png"))
--		:move(730,358)
--		:setAnchorPoint(cc.p(0.5,0.5))
--		:setFontName("fonts/round_body.ttf")
--		:setPlaceholderFontName("fonts/round_body.ttf")
--		:setFontSize(24)
--		:setPlaceholderFontSize(24)
--		:setMaxLength(26)
--		:setInputFlag(cc.EDITBOX_INPUT_FLAG_PASSWORD)
--		:setInputMode(cc.EDITBOX_INPUT_MODE_SINGLELINE)
--		:setPlaceHolder("6-26位英文字母，数字，下划线组合")
--		:addTo(self)
--	--条款协议
--	self.cbt_Agreement = ccui.CheckBox:create("Regist/choose_regist_0.png","","Regist/choose_regist_1.png","","")
--		:move(510,183)
--		:setSelected(RegisterView.bAgreement)
--		:setTag(RegisterView.CBT_AGREEMENT)
--		:addTo(self)

--	--显示协议
--	ccui.Button:create("Regist/bt_regist_agreement.png","")
--		:setTag(RegisterView.BT_AGREEMENT)
--		:move(780,181)
--		:addTo(self)
--		:addTouchEventListener(btcallback)


end


function RegisterView:onButtonClickedEvent(tag,ref)
	if tag == RegisterView.BT_RETURN then
		self:getParent():getParent():onShowLogon()
	elseif tag == RegisterView.BT_AGREEMENT then
		self:getParent():getParent():onShowService()
	elseif tag == RegisterView.BT_CODE then
		-- GlobalUserItem.bVisitor = true
		self:getParent():getParent():onSDKCode(self.edit_Account:getText())
	elseif tag == RegisterView.BT_REGISTER then
		-- 判断 非 数字、字母、下划线、中文 的帐号
		local szAccount = self.edit_Account:getText()
		local filter = string.find(szAccount, "^[a-zA-Z0-9_\128-\254]+$")
		if nil == filter then
			showToast(self, "帐号包含非法字符, 请重试!", 1)
			return
		end
		szAccount = string.gsub(szAccount, " ", "")
		local szPassword = string.gsub(self.edit_Password:getText(), " ", "")
		local szRePassword = string.gsub(self.edit_RePassword:getText(), " ", "")
		local bAgreement = self:getChildByTag(RegisterView.CBT_AGREEMENT):isSelected()
		local szSpreader = string.gsub(self.edit_Spreader:getText(), " ", "")
		self:getParent():getParent():onRegister(szAccount,szPassword,szRePassword,bAgreement,szSpreader)
	end
end

function RegisterView:setAgreement(bAgree)
	self.cbt_Agreement:setSelected(bAgree)
end

return RegisterView